Kuo['home'] = {
  //每个步骤初始化
  init: function () {
    p("home init ok");

    var html = kuotpl(function () {
      /*
                 <style>
                   
                 </style>
                  <div id="LAY_app" class="layadmin-tabspage-none">
          <div class="layui-layout layui-layout-admin">
            <div class="layui-header">
              <!-- 头部区域 -->
              <ul class="layui-nav layui-layout-left">
                <li class="layui-nav-item layadmin-flexible" lay-unselect>
                  <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">
                    <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
                  </a>
                </li>

                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                 <a href="javascript:window.open(window.WZHOST);" title="前台">
                    <i class="layui-icon layui-icon-website"></i>
                  </a>
                </li>
                <li class="layui-nav-item" lay-unselect>
                  <a href="javascript:window.location.href='?';"  title="刷新">
                    <i class="layui-icon layui-icon-refresh-3"></i>
                  </a>
                </li>

                <li class="layui-nav-item" lay-unselect>
                  <a href="javascript:Kuo['home'].closeall();" style="height:35px;line-height:35px;padding-top:6px;"  title="删除table">
                   
                    <i class="layui-icon layui-icon-delete" style="font-size:28px;color:green;"></i>
                  </a>
                </li>

              
                
              </ul>
              <ul class="layui-nav layui-layout-right"   lay-filter="layadmin-layout-right">
                
               
           
                <li class="layui-nav-item" lay-unselect>
                  <a href="javascript:;">
                    <cite id="username">admin</cite>
                  </a>
                  <dl class="layui-nav-child">
                    <dd><a  id="quanxianzu">admin</a></dd>
                  
                    <hr>
                    <dd layadmin-event="logout" style="text-align: center;"><a  id="quite"> 退出</a></dd>
                  </dl>
                </li>
                
              </ul>
            </div>
            
         
            <div class="layui-side layui-side-menu">
              <div class="layui-side-scroll">
                <div class="layui-logo" >
                  <span><a href="{{SOFTHTTP}}" target="_blank">{{ SOFTNAME+' V'+ SOFTVER }}</a></span>
                </div>
                
                <ul class="layui-nav layui-nav-tree woshitaidedan" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">
                
                </ul>
              </div>
            </div>

            <!-- 页面标签 -->
          
              
              <div class="layui-tab " lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">

              
                
                 <ul class="layui-tab-title layadmin-pagetabs" id="LAY_app_tabsheader">
                 
                      <li class="layui-this home" id="morenhome" data="home/main@@首页">
                        <i class="layui-icon layui-icon-home"></i>
                      
                      </li>

                  </ul>
                  

                  <div class="layui-tab-content layui-body" id="LAY_app_body">
                    <div class="tashilisthha layui-tab-item home layui-show">
                      <div class="layui-card">
                        <div class="layui-card-header">更新日志</div>
                        <div class="layui-card-body">
                          <iframe  style="width:100%;min-height:450px;" frameborder="0" src="//www.kuosoft.com/log.html"></iframe>
                        </div>
                      </div>
                      <div  id="myhomes">
                      </div>
                    
                    </div>
                     
                     
                  </div>

              </div>
            
            <div class="layadmin-body-shade" layadmin-event="shade"></div>
          </div>
        </div>
      */
    });
    $("body").html(html);


    $("#LAY_app_flexible").click(function () {


      if ($(window).width() > 720) {

        if ($('.layadmin-side-shrink').length > 0) {
          $("#LAY_app").removeClass('layadmin-side-shrink');
        } else {
          $("#LAY_app").addClass('layadmin-side-shrink');
        }

      } else {
        $(".layui-layout-admin .layui-side").css({
          left: 220
        });
        $(".layadmin-body-shade").show();
      }


    });

    $(".layadmin-body-shade").click(function () {
      $(".layui-layout-admin .layui-side").css({
        left: 0
      });
      $(".layadmin-body-shade").hide();
    });

    Kuo['home'].xuanadmin();
    Kuo['home'].xuancaidan();
    layui.element.render();

  }, xuanadmin() {
    $("#username").html(Kuo.DATA.user.admininame);
    $("#quanxianzu").html(Kuo.DATA.user.admingroupsname);
    $("#quite").click(function () {
      //发送退出命令
      $.get(PLUG + "quite?apptoken="+APPTOKEN, {}, function (data) {

        if (data.token && data.token != "") {
          TOKEN = data.token;
        }
       
        loadjs("admin/adminlogin");
      });



    });
  },
  closeall() {

    $("#LAY_app_tabsheader li").each(function () {
      if (!$(this).hasClass('home')) {
        $(this).remove();
      }

    });
    $("#LAY_app_tabsheader .home").addClass('layui-this');
    $("#LAY_app_body .layui-tab-item").each(function () {
      if (!$(this).hasClass('home')) {
        $(this).remove();
      }
    });


    $("#LAY_app_body .home").addClass('layui-show');
    layer.msg("清空tab成功");




  },
  xuanhtml(zcaidan, ini) {
    var xhtml = '<dl class="layui-nav-child">';

    for (var men in zcaidan) {
      xhtml += '<dd data-name="' + zcaidan[men].name + '" >';
      if (zcaidan[men].typeico && zcaidan[men].typeico != "") {
        xhtml += '<i class="layui-icon ' + zcaidan[men].typeico + '"></i>';
      }
      if (zcaidan[men].link && zcaidan[men].link != "") {
        var jjj = 'loadurl(\'' + zcaidan[men].link + '\',\'' + zcaidan[men].name + '\')';
      } else {
        var jjj = 'loadjs(\'' + ini + "/" + '' + men + '\',\'' + zcaidan[men].name + '\')';
      }

      if (zcaidan[men].men && zcaidan[men].men.length > 0) {
        jjj = 'void(0)';
        xhtml += '<a href="javascript:' + jjj + ';"> ' + zcaidan[men].name + '</a>';
        xhtml += Kuo['home'].xuanhtml(zcaidan[men].men, ini + "/" + '' + men);
      } else {
        xhtml += '<a href="javascript:' + jjj + ';">' + zcaidan[men].name + '</a>';
      }


    }
    xhtml += '</dl>';

    return xhtml;
  },
  xuancaidan() {

    var html = '';
    var caidan = Kuo.DATA.user.adminmen;
    for (var ini in caidan) {

      if (caidan[ini].name == "") {
        continue;
      }



      html += '<li data-name="home" class="layui-nav-item '+( caidan[ini].main  !=0?'airobt-main':'')+'" lay-direction="2">';

        if( caidan[ini].main == 0){

        

          if (caidan[ini].men && caidan[ini].men.length != 0) {
            var jjj = 'void(0)';
          } else {
            var jjj = 'loadjs(\'' + ini + '\')';
          }

          html += '<a href="javascript:' + jjj + ';" lay-tips="' + caidan[ini].name + '" >';
          if (caidan[ini].typeico && caidan[ini].typeico != "") {
            html += '<i class="layui-icon ' + caidan[ini].typeico + '"></i>';
          }

          html += '<cite>' + (caidan[ini].name == "" ? ini : caidan[ini].name) + '</cite>';
          html += '</a>';

      }

 

        if (caidan[ini].men && caidan[ini].men.length != 0) {
          if( caidan[ini].main == 0){
            html += '<dl class="layui-nav-child">';
          }
          var zcaidan = caidan[ini].men;

          for (var men in zcaidan) {
            if( caidan[ini].main == 0){
              html += '<dd data-name="' + zcaidan[men].name + '" >';
            }else{
              html +='</li><li data-name="home" class="layui-nav-item  airobt-main" lay-direction="2">';

            }
            if (zcaidan[men].typeico && zcaidan[men].typeico != "") {
              html += '<i class="layui-icon ' + zcaidan[men].typeico + '"></i>';
            }
            if (zcaidan[men].link && zcaidan[men].link != "") {
              var jjj = 'loadurl(\'' + zcaidan[men].link + '\',\'' + zcaidan[men].name + '\')';
            } else {
              var jjj = 'loadjs(\'' + ini + "/" + '' + men + '\',\'' + zcaidan[men].name + '\')';
            }
            if (zcaidan[men].men) {
              jjj = 'void(0)';
              html += '<a href="javascript:' + jjj + ';">' + zcaidan[men].name + '</a>';
              html += Kuo['home'].xuanhtml(zcaidan[men].men, ini + "/" + '' + men);

            } else {
              html += '<a href="javascript:' + jjj + ';">' + zcaidan[men].name + '</a>';
            }
            if( caidan[ini].main == 0){
              html += '</dd>';
            }
          }
          if( caidan[ini].main == 0){
             html += '</dl>';
          }
        }

      
      html += '</li>';
    }

    $(".woshitaidedan").html(html);

    setTimeout(function(){

      Kuo['home'].tongji();
    
      

    },500);

  },tongji(){

    apptongxin( PLUG+'hometongji'+"/"+TOKEN+"/"+'get' ,{},function(data){

      if(data.code == 99){
        window.location.href='?';
        return ;
      }
      var htmlx = "";
      htmlx +='<div class="layui-card">';
      htmlx +='<div class="layui-card-header">数据统计</div>';
      htmlx +='<div class="layui-card-body">';
    
      htmlx +='    <div class="layadmin-backlog" lay-anim="" lay-indicator="inside" lay-arrow="none" style="width: 100%;">';

      htmlx +='        <ul class="layui-row layui-col-space10 layui-this">';

      if(data.data && typeof(data.data) != "string"){
        for(var ss in data.data){
          var linshi = data.data[ss];

          htmlx +='        <li class="layui-col-xs6  layui-col-md4">';
          htmlx +='            <a class="layadmin-backlog-body">';
          htmlx +='            <h3>'+linshi['TABLE_COMMENT']+' '+linshi['TABLE_NAME']+'</h3>';
          htmlx +='            <p><cite>'+linshi['TABLE_ROWS']+'</cite></p>';
          htmlx +='            </a>';
          htmlx +='        </li>';

        }

      }


      htmlx +='        </ul>';
      htmlx +='      ';
      htmlx +='    <div style="clear:both;"></div>';

      htmlx +='</div></div></div></div>';


      if(data.data  && typeof(data.data) != "string" ){
        $("#myhomes").html(htmlx);
      }
    },"get");


    setTimeout(function(){
      Kuo['home'].tongji();

    },60000);
  }
};
Kuo['home'].init();